package cn.kent;

import java.util.ArrayList;
import java.util.List;

/**
 * 树的中序遍历； 左中右
 */
public class MyTest {
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        if (root == null) {
            return list;
        }

        if (root.left == null && root.right == null) {
            list.add(root.val);
            return list;
        }

        curcul(root, list);

        return list;
    }

    public void curcul(TreeNode node, List<Integer> list) {
        if (node.left != null) {
            this.curcul(node.left, list);
        }
        if (node != null) {
            // 加入 父节点
            list.add(node.val);
        }
        if (node.right != null) {
            this.curcul(node.right, list);
        }
    }

    public static void main(String[] args) {
    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    public TreeNode() {
    }

    public TreeNode(int val) {
        this.val = val;
    }

    public TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }

}

